//
//  XMPhotoScanController.m
//  XiaoMiao
//
//  Created by 23 on 2018/3/22.
//  Copyright © 2018年 smallyou. All rights reserved.
//

#import "XMPhotoScanController.h"
#import "XMAlbumScrollView.h"

@interface XMPhotoScanController ()

/**scrollView*/
@property(nonatomic,weak) XMAlbumScrollView *scrollView;

/**对比照*/
@property(nonatomic,weak) XMAlbumScrollView *standardView;

/**button*/
@property(nonatomic,weak) UIButton *cancelButton;

@end

@implementation XMPhotoScanController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = kRGBColor(230, 230, 230);
    
    WEAKSELF
    XMAlbumScrollView *scrollView = [[XMAlbumScrollView alloc] init];
    scrollView.backgroundColor = [UIColor blackColor];
    scrollView.isScanner = YES;
    scrollView.isCompare = self.isCompare;
    scrollView.callback = ^(CGFloat zoom, CGPoint offset) {
        weakSelf.standardView.zoom = zoom;
    };
    [self.view addSubview:scrollView];
    self.scrollView = scrollView;
    
    
    XMAlbumScanModel *imageModel = [[XMAlbumScanModel alloc] init];
    imageModel.imageUrl = self.imageUrl;
    UIImage *placeholderImg = nil;
    if (placeholderImg == nil) {
        placeholderImg = [UIImage imageNamed:@"ic_common_avatar_default"];
    }
    imageModel.image = placeholderImg;
    scrollView.imageModel = imageModel;
    scrollView.isStandard = NO;
    scrollView.backgroundColor = kRGBColor(230, 230, 230);
    
    
    if (self.isCompare) {
        
        XMAlbumScrollView *standardView = [[XMAlbumScrollView alloc] init];
        standardView.isScanner = NO;
        standardView.callback = ^(CGFloat zoom, CGPoint offset) {
            weakSelf.scrollView.zoom = zoom;
        };
        [self.view addSubview: standardView];
        self.standardView = standardView;
        
        XMAlbumScanModel *imageModel = [[XMAlbumScanModel alloc] init];
        imageModel.imageUrl = self.standardUrl;
        UIImage *placeholderImg = nil;
        if (placeholderImg == nil) {
            placeholderImg = [UIImage imageNamed:@"ic_common_avatar_default"];
        }
        imageModel.image = placeholderImg;
        standardView.imageModel = imageModel;
        standardView.isStandard = NO;
        standardView.backgroundColor = kRGBColor(230, 230, 230);
        
    }
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"ic_album_cha"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(actionCancel) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    self.cancelButton = button;
}

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    
    
    self.scrollView.frame = CGRectMake(0, 0.5 * (self.view.app_height - 300), self.view.app_width, 300);
    
    [self.cancelButton sizeToFit];
    CGPoint center = self.view.center;
    self.cancelButton.center = CGPointMake(center.x, self.view.app_height - 100);
    
    if (self.isCompare) {
        self.standardView.frame = CGRectMake(0, 0.5 * (self.view.app_height - 300), self.view.app_width * 0.5, 300);
        self.scrollView.frame = CGRectMake(self.view.app_width * 0.5, 0.5 * (self.view.app_height - 300), self.view.app_width * 0.5, 300);
    }
    
}

- (void)actionCancel
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
